package wifiunion.com.notice.presenter;

import java.lang.ref.WeakReference;
import java.util.HashMap;

import wifiunion.com.notice.BaseCallBack;
import wifiunion.com.notice.HomePageDetailContact;
import wifiunion.com.notice.model.HomepageModel;

/**
 * Created by Administrator on 2018/7/29.
 */

public class HomepagePresenter<T extends HomePageDetailContact.MainView> implements HomePageDetailContact.Presenter, HomePageDetailContact.Callback {

    /**
     * 0 获取首页
     * 1 获取用户
     */
    private int type;


    private WeakReference<T> mRef;

    private HomepageModel homepageModel;

    public HomepagePresenter(T t, int type) {

        mRef = new WeakReference<T>(t);
        this.type = type;
        homepageModel = new HomepageModel();
    }

    @Override
    public void onSuccess(Object data) {

        if (mRef == null && mRef.get()== null) {
            return;
        }
        if (type == 0) {
            mRef.get().getHomepageSuccess(data);
        } else if (type == 1) {
            mRef.get().getUserDetailSuccess(data);
        }
    }

    @Override
    public void onServerFailed(Object errorObj) {
        if (mRef == null && mRef.get()== null) {
            return;
        }
        if (type == 0) {
            mRef.get().getHomepageFailed(errorObj);
        } else if (type == 1) {
            mRef.get().getUserDetailFailed(errorObj);
        }
    }

    @Override
    public void onNetFailed() {
        if (mRef == null && mRef.get()== null) {
            return;
        }
        if (type == 0) {
            mRef.get().getHomepageFailed("网络异常");
        } else if (type == 1) {
            mRef.get().getUserDetailFailed("网络异常");
        }
    }

    @Override
    public void start() {

    }

    @Override
    public void start(HashMap<String, Object> param1s) {

    }

    @Override
    public void downloadPercent(long percent) {

    }

    @Override
    public void getPackageSize(long size) {

    }


    public void getUserRequest(HashMap<String, Object> param) {
        homepageModel.getUserRequest(param, this);
    }

    public void getHomepageRequest(HashMap<String, Object> param) {
        homepageModel.getHomepageRequest(param, this);
    }
}
